﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace AGrandVenture
{
    class SlimeEye : Enemy
    {
        static string name = "Slime Eye";
        static Texture2D texture = Game1.slimeEyeSheet;
        static Rectangle initialFrame = new Rectangle(0, 0, 48, 48);
        Color tintColor;
        int hp = 60;
        int xpValue = 10;
        int damageDealt = 5;
        int damageTaken = 3;
        float moveSpeed = 60f;
        float lootChance = 0.12f;
        bool primarilyRed = true;
        bool primarilyBlue = true;

        public SlimeEye(Vector2 worldLocation)
            : base(name, worldLocation, texture, initialFrame)
        {
            base.HasClaws = false;
            base.NeedsToFlip = true;
            base.NeedsToRotate = false;
            base.HasRangedAttack = false;
            base.HasMeleeAttack = true;
            base.MoveSpeed = moveSpeed;
            base.ChanceToDropLoot = lootChance;
            base.DamageDealt = damageDealt;
            base.DamageTaken = damageTaken;
            base.HP = hp;
            base.XP_Value = xpValue;

            //Determine random color of slime
            Random rnd = new Random();
            int r, g, b = 0;

            r = rnd.Next(0, 255);
            g = rnd.Next(0, 255);
            b = rnd.Next(0, 255);

            primarilyRed = (r >= 150 && g < 150 && b < 150) ? true : false;
            primarilyBlue = (b >= 150 && g < 150 && b < 150) ? true : false;

            tintColor = new Color(r, g, b);
            base.EnemyBase.TintColor = tintColor;

            //Add walk animation
            base.EnemyBase.AddFrame(new Rectangle(48, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(96, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(48, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(0, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(48, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(96, 0, 48, 48), 0.2f);
        }

        public override void performMeleeAttack()
        {
            base.CurrentlyAttacking = true;
            base.EnemyBase.ClearFrames();
            base.MoveSpeed = 0f;

            //Switch to attack animation
            base.EnemyBase.AddFrame(new Rectangle(48, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(144, 0, 48, 48), 0.2f);
            if (!primarilyBlue)
            {
                base.EnemyBase.AddFrame(new Rectangle(96, 48, 48, 48), 0.2f);
                base.EnemyBase.AddFrame(new Rectangle(144, 48, 48, 48), 0.2f);
                base.EnemyBase.AddFrame(new Rectangle(192, 48, 48, 48), 0.2f);
            }
            else if (!primarilyRed)
            {
                base.EnemyBase.AddFrame(new Rectangle(240, 48, 48, 48), 0.2f);
                base.EnemyBase.AddFrame(new Rectangle(288, 48, 48, 48), 0.2f);
                base.EnemyBase.AddFrame(new Rectangle(0, 96, 48, 48), 0.2f);
            }
            else
            {
                base.EnemyBase.AddFrame(new Rectangle(240, 0, 48, 48), 0.2f);
                base.EnemyBase.AddFrame(new Rectangle(288, 0, 48, 48), 0.2f);
                base.EnemyBase.AddFrame(new Rectangle(0, 48, 48, 48), 0.2f);
            }

        }

        public override void endOfAttack()
        {
            base.CurrentlyAttacking = false;
            base.MoveSpeed = moveSpeed;

            base.EnemyBase.ClearFrames();
            base.EnemyBase.AddFrame(new Rectangle(48, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(96, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(48, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(0, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(48, 0, 48, 48), 0.2f);
            base.EnemyBase.AddFrame(new Rectangle(96, 0, 48, 48), 0.2f);
        }
    }
}
